package com.fyx.controller;

import com.alibaba.fastjson.JSONObject;
import com.fyx.annotation.Log;
import com.fyx.entity.*;
import com.fyx.service.IMaiInfoService;
import com.fyx.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "游戏功能相关")
@RestController
@RequestMapping("/api/mai")
@RequiredArgsConstructor
public class MaiInfoController {

    @Autowired
    private IMaiInfoService maiInfoService;

    @Log("埋点数据")
    @ApiOperation("埋点数据")
    @GetMapping(value="maiInfo")
    @PreAuthorize("@el.check('maiInfo:list')")
    public ResponseEntity<Object> maiInfo(MaiInfo maiInfo, Pageable pageable){
        Map mapResult = maiInfoService.getMaiInfo(maiInfo,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);
    }

    @Log("埋点广告数据")
    @ApiOperation("埋点广告数据")
    @GetMapping(value="maiAdInfo")
    @PreAuthorize("@el.check('maiAdInfo:list')")
    public ResponseEntity<Object> maiAdInfo(MaiAdInfo maiAdInfo, Pageable pageable){
        Map mapResult = maiInfoService.getMaiAdInfo(maiAdInfo,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);
    }


    @Log("埋点房间数据")
    @ApiOperation("埋点房间数据")
    @GetMapping(value="maiRoomsInfo")
    @PreAuthorize("@el.check('maiRoomsInfo:list')")
    public ResponseEntity<Object> maiRoomsInfo(MaiRoomsInfo maiRoomsInfo, Pageable pageable){
        Map mapResult = maiInfoService.getMaiRoomsInfo(maiRoomsInfo,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);
    }

    @Log("埋点分享数据")
    @ApiOperation("埋点分享数据")
    @GetMapping(value="maiShareInfo")
    @PreAuthorize("@el.check('maiShareInfo:list')")
    public Map maiShareInfo(MaiShareInfo maiShareInfo, Pageable pageable){
        Map mapResult = maiInfoService.getMaiShareInfo(maiShareInfo,pageable);
        return mapResult;
    }

    @PostMapping(value = "getMaiAdInfo")
    @PreAuthorize("@el.check('maiAdInfo:list')")
    public  List<MaiAdInfo> getMaiAdInfo(@Validated @RequestBody JSONObject jsonObject){
        String channel= jsonObject.getString("channel");
        Integer time=Integer.valueOf(jsonObject.getString("time")) ;
        List<MaiAdInfo> getMaiAdInfo = maiInfoService.getMaiAdInfo(time,channel);
        return getMaiAdInfo;
    }

    @PostMapping(value = "getMaiRoomsInfo")
    @PreAuthorize("@el.check('maiRoomsInfo:list')")
    public  List<MaiRoomsInfo> getMaiRoomsInfo(@Validated @RequestBody JSONObject jsonObject){
        String channel= jsonObject.getString("channel");
        Integer time=Integer.valueOf(jsonObject.getString("time")) ;
        List<MaiRoomsInfo> getMaiRoomsInfo = maiInfoService.getMaiRoomsInfo(time,channel);
        return getMaiRoomsInfo;
    }

    @PostMapping(value = "getMaiInfo")
    @PreAuthorize("@el.check('maiInfo:list')")
    public  List<MaiInfo> getMaiInfo(@Validated @RequestBody JSONObject jsonObject){
        String channel= jsonObject.getString("channel");
        Integer time=Integer.valueOf(jsonObject.getString("time")) ;
        List<MaiInfo> getMaiInfo = maiInfoService.getMaiInfo(time,channel);
        return getMaiInfo;
    }

    @PostMapping(value = "getMaiShareInfo")
    @PreAuthorize("@el.check('maiAdInfo:list')")
    public  List<MaiShareInfo> getMaiShareInfo(@Validated @RequestBody JSONObject jsonObject){
        String channel= jsonObject.getString("channel");
        Integer time=Integer.valueOf(jsonObject.getString("time")) ;
        List<MaiShareInfo> getMaiShareInfo = maiInfoService.getMaiShareInfo(time,channel);
        return getMaiShareInfo;
    }
}
